package ulmermark.demo.rest.spring;

import java.util.*;

import org.springframework.stereotype.Service;

@Service
public class OrdersService {

    private static Map<String,Order> orders = new HashMap<String,Order>();
    private static int nextId = 6;
    static {
    	for( int inx=0; inx < 10000; inx++){
	        orders.put(""+inx, new Order(""+inx, "Bob-"+inx, inx));
    	}
	}

    public Order get(String id) {
        return orders.get(id);
    }

    public List<Order> getAll() {
        return new ArrayList<Order>(orders.values());
    }

    public void save(final Order order) {
        if (order.getId() == null) {
            order.setId(String.valueOf(nextId++));
        }

        orders.put(order.getId(), order);
    }

    public void remove(String id) {
        orders.remove(id);
    }

}
